package org.htmlparser.filters;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Tag;

public class HasParentFilter
  implements NodeFilter
{
  protected NodeFilter mParentFilter;
  protected boolean mRecursive;

  public HasParentFilter()
  {
    this(null);
  }

  public HasParentFilter(NodeFilter paramNodeFilter)
  {
    this(paramNodeFilter, false);
  }

  public HasParentFilter(NodeFilter paramNodeFilter, boolean paramBoolean)
  {
    setParentFilter(paramNodeFilter);
    setRecursive(paramBoolean);
  }

  public boolean accept(Node paramNode)
  {
    boolean bool = false;
    if ((!(paramNode instanceof Tag)) || (!(((Tag)paramNode).isEndTag())))
    {
      Node localNode = paramNode.getParent();
      if ((localNode != null) && (getParentFilter() != null))
      {
        bool = getParentFilter().accept(localNode);
        if ((!(bool)) && (getRecursive()))
          bool = accept(localNode);
      }
    }
    return bool;
  }

  public NodeFilter getParentFilter()
  {
    return this.mParentFilter;
  }

  public boolean getRecursive()
  {
    return this.mRecursive;
  }

  public void setParentFilter(NodeFilter paramNodeFilter)
  {
    this.mParentFilter = paramNodeFilter;
  }

  public void setRecursive(boolean paramBoolean)
  {
    this.mRecursive = paramBoolean;
  }
}